home *** CD-ROM | disk | FTP | other *** search
/ HyperLib 1997 Winter - Disc 1 / HYPERLIB-1997-Winter-CD1.ISO.7z / HYPERLIB-1997-Winter-CD1.ISO / オンラインウェア / UTIL / Folder・Icon・Opener 1.0.1.sit / Folder•Icon•Opener 1.0.1 / source code / sources / FIOpen.draw.c < prev    next >
Text File  |  1996-05-05  |  5KB  |  184 lines

  1. /*
  2.  *--------------------------------------------------------------
  3.  * FIOpen.draw.c
  4.  *--------------------------------------------------------------
  5.  *    Copyright ゥ Fumio Rokkaku, 1996
  6.  *--------------------------------------------------------------
  7.  */
  8. #pragma once
  9.  
  10. /* System Headers */
  11. #include <QuickDraw.h>
  12. #include <Windows.h>
  13. #include <Dialogs.h>
  14. #include <Controls.h>
  15. #include <Palettes.h>
  16. #include <OSUtils.h>
  17. #include <Icons.h>
  18. #include <Gestalt.h>
  19. #include <Errors.h>
  20.  
  21. /* Project Headers */
  22. #include "FIOpen.h"
  23.  
  24. /*
  25.  *--------------------------------------------------------------
  26.  *    global flags to check QuickDraw version
  27.  *--------------------------------------------------------------
  28.  */
  29. long    gQDVersion;
  30.  
  31. /*
  32.  *--------------------------------------------------------------
  33.  *    type definitions for custom drawing routines
  34.  *--------------------------------------------------------------
  35.  */
  36. typedef struct {
  37.     RectPtr    rect;
  38.     Boolean    flag;
  39. } DrawPrmRec, *DrawPrmPtr;
  40.  
  41. /*
  42.  *--------------------------------------------------------------
  43.  *    prototypes of device loop callback routines
  44.  *--------------------------------------------------------------
  45.  */
  46. static pascal void DrawEachRaisedRect(short dpt, short flg, GDHandle gdv, long ref);
  47.  
  48. /*
  49.  *--------------------------------------------------------------
  50.  *    static function prototypes used within this source
  51.  *--------------------------------------------------------------
  52.  */
  53. static void DrawDeepRaisedRect(RectPtr, GDHandle);
  54. static void DrawBMapRaisedRect(RectPtr);
  55.  
  56. /*
  57.  *--------------------------------------------------------------
  58.  * GetQuickDrawVersion
  59.  *--------------------------------------------------------------
  60.  *    frame bold round rect to default button
  61.  *--------------------------------------------------------------
  62.  */
  63. void GetQuickDrawVersion(void)
  64. {
  65.     OSErr    result;
  66.  
  67.     result = Gestalt(gestaltQuickdrawVersion, &gQDVersion);
  68.     if (result != noErr) {
  69.         gQDVersion = gestaltOriginalQD;
  70.     }
  71. }
  72. /*
  73.  *--------------------------------------------------------------
  74.  * RaisedRect
  75.  *--------------------------------------------------------------
  76.  *    draw rased rectangle frame
  77.  *--------------------------------------------------------------
  78.  */
  79. void RaisedRect(const RectPtr theRect)
  80. {
  81.     Rect        drawRect;
  82.     PenState    curPen;
  83.  
  84.     GetPenState(&curPen);
  85.     PenNormal();
  86.  
  87.     drawRect.top    = theRect->top;
  88.     drawRect.left    = theRect->left;
  89.     drawRect.bottom    = theRect->bottom -1;
  90.     drawRect.right    = theRect->right -1;
  91.  
  92.     /* check the QuickDraw version */
  93.     if (gQDVersion >= gestalt8BitQD) {
  94.         DeviceLoopDrawingUPP RaisedUPP;
  95.  
  96.         RaisedUPP = NewDeviceLoopDrawingProc(DrawEachRaisedRect);
  97.         /* call the device loop callback */
  98.         if (RaisedUPP != nil) {
  99.             RgnHandle    drawRgn = NewRgn();
  100.             RectRgn(drawRgn, &drawRect);
  101.             DeviceLoop(drawRgn, RaisedUPP, (long)&drawRect, 0);
  102.             DisposeRoutineDescriptor(RaisedUPP);
  103.             DisposeRgn(drawRgn);
  104.         }
  105.     } else {
  106.         DrawBMapRaisedRect(&drawRect);
  107.  
  108.     }
  109.     SetPenState(&curPen);
  110. }
  111. /*
  112.  *--------------------------------------------------------------
  113.  * DrawEachRaisedRect
  114.  *--------------------------------------------------------------
  115.  *    raised rectangle drawing device loop callback
  116.  *--------------------------------------------------------------
  117.  */
  118. static pascal void DrawEachRaisedRect(
  119.     short        howDeep,
  120.     short        theFlag,
  121.     GDHandle    theDevice,
  122.     long        userData)
  123. {
  124.     #pragma unused(theFlag)
  125.  
  126.     RectPtr    drawRect = (RectPtr)userData;
  127.     if (howDeep > 1) {
  128.         DrawDeepRaisedRect(drawRect, theDevice);
  129.     } else {
  130.         DrawBMapRaisedRect(drawRect);
  131.     }
  132. }
  133. /*
  134.  *--------------------------------------------------------------
  135.  * DrawDeepRaisedRect
  136.  *--------------------------------------------------------------
  137.  *    raised rectangle drawing routine on the deep device
  138.  *--------------------------------------------------------------
  139.  */
  140. static void DrawDeepRaisedRect(RectPtr theRect, GDHandle theDevice)
  141. {
  142.     RGBColor    foreColor, backColor, grayColor;
  143.  
  144.     GetForeColor(&foreColor);
  145.     GetBackColor(&backColor);
  146.     grayColor = foreColor;
  147.  
  148.     if (GetGray(theDevice, &backColor, &grayColor)) {
  149.         ForeColor(whiteColor);
  150.         MoveTo(theRect->left,  theRect->bottom);
  151.         LineTo(theRect->left,  theRect->top);
  152.         LineTo(theRect->right, theRect->top);
  153.         RGBForeColor(&grayColor);
  154.         LineTo(theRect->right, theRect->bottom);
  155.         LineTo(theRect->left,  theRect->bottom);
  156.         RGBForeColor(&foreColor);
  157.     } else {
  158.         DrawBMapRaisedRect(theRect);
  159.     }
  160. }
  161. /*
  162.  *--------------------------------------------------------------
  163.  * DrawBMapRaisedRect
  164.  *--------------------------------------------------------------
  165.  *    raised rectangle drawing routine on the bitmap device
  166.  *--------------------------------------------------------------
  167.  */
  168. static void DrawBMapRaisedRect(RectPtr theRect)
  169. {
  170.     long    darkPat[2], litePat[2];
  171.  
  172.     darkPat[0] = darkPat[1] = 0xFFFFFFFF;
  173.     litePat[0] = litePat[1] = 0xAA55AA55;
  174.  
  175.     PenPat((PatPtr)litePat);
  176.     MoveTo(theRect->left,  theRect->bottom);
  177.     LineTo(theRect->left,  theRect->top);
  178.     LineTo(theRect->right, theRect->top);
  179.  
  180.     PenPat((PatPtr)darkPat);
  181.     LineTo(theRect->right, theRect->bottom);
  182.     LineTo(theRect->left,  theRect->bottom);
  183. }
  184.